/*
 * File:   main.cpp
 * Author: Twelve
 *
 * Created on 30 Декабрь 2010 г., 19:18
 */



#include "main.h"
#include "ftechinfo.h"






vector<string> Log1;
WINDOW * win[SCREENS];

int main(int argc, char** argv) {

    int tohit, tohit_mon;


    int ch;
    Log1.clear();

    Creature Mob(MOB, R_ELVES);
    Creature Player(PC, R_HUMANS);

    vector<Creature> Mobs;

    tohit = tohit_mon = 11;

    for (int i = 0; i < 5; i++) {
        Mobs.push_back(Creature(MOB, R_ELVES));
        //Mobs[i].SetTohit(tohit);
        //Mobs[i].SetFightingStyle(S_1H_SWORD);


    }

    Mob.SetMonAtkSpd(Player.Dex);


    InitScreen(win);

    printw("Let the battle begins... Ver. %g \n", VER);
    printw("Press any key to start.\n");

    //printw("mob ne vector hp : %d\n", m.hp);

//    for (int i = 0; i < 5; i++) {
//        printw("mobisdead hp %s. \n", Mobs[i].GetHp());
//    }



    refresh();
    getch();

    Player.SetFightingStyle(S_1H_SWORD);
    Mob.SetFightingStyle(S_1H_SWORD);

    Player.SetTohit(tohit);
    Mob.SetTohit(tohit);

    int mobnum = 0;


    while ((ch = getch()) != KEY_F(1)) {
        switch (ch) {
            case 32:

                if ((Player.IsDead == FALSE) & (Mob.IsDead == FALSE)) {
                    SimpleDD(Player, Mob);
                    DrawScreen(Player);
                    break;
                } else {
                    clear();
                    printw("someone died");
                    refresh();
                    break;
                }
            case 'h':
                DrawHelp();
                DrawScreen(Player);
                break;
        }
    }
    //getch();
    //delwin(BigWindows);
    for (int i = 0; i < SCREENS; i++) {
        delwin(win[i]);
    }
    endwin(); /* End curses mode		  */



    return 0;
}

void InitScreen(WINDOW **locwin) {
    srand(time(0));

    initscr(); /* Start curses mode 		  */

    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    curs_set(0);
    //use_default_colors();
    if (has_colors() == FALSE) {
        endwin();
        printf("Your terminal does not support color\n");
        exit(1);
    }
    start_color();

    init_pair(0, COLOR_BLACK, COLOR_DEFAULT);
    init_pair(1, COLOR_BLUE, COLOR_DEFAULT);
    init_pair(2, COLOR_GREEN, COLOR_DEFAULT);
    init_pair(3, COLOR_CYAN, COLOR_DEFAULT);
    init_pair(4, COLOR_RED, COLOR_DEFAULT);
    init_pair(5, COLOR_MAGENTA, COLOR_DEFAULT);
    init_pair(6, COLOR_YELLOW, COLOR_DEFAULT);
    init_pair(7, COLOR_WHITE, COLOR_DEFAULT);
    init_pair(8, COLOR_BLACK, COLOR_DEFAULT);





    /*
     **************************************
     *
     *
     * Задание окон интерфейса
     *
     *************************************
     */
    int xbeg[SCREENS], ybeg[SCREENS];
    int y_size[SCREENS], x_size[SCREENS];

    xbeg[S_MAINBATTLE] = 0;
    ybeg[S_MAINBATTLE] = 0;
    y_size[S_MAINBATTLE] = 10;
    x_size[S_MAINBATTLE] = 49;

    xbeg[S_MAINSTAT] = 50;
    ybeg[S_MAINSTAT] = 0;
    y_size[S_MAINSTAT] = 10;
    x_size[S_MAINSTAT] = 30;

    xbeg[S_BWIDGET] = 10;
    ybeg[S_BWIDGET] = 11;
    y_size[S_BWIDGET] = 12;
    x_size[S_BWIDGET] = 20;

    for (int i = 0; i < SCREENS; i++) {
        locwin[i] = newwin(y_size[i], x_size[i], ybeg[i], xbeg[i]);
        wclear(locwin[i]);
    };
    refresh();

}
